<%-- 
    Document   : add
    Created on : Nov 23, 2014, 1:59:08 PM
    Author     : Marian Lorenc, 374122
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>  

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><fmt:message key="rental.addNew" /></title>
    </head>
    <body>
        <div class="container">
            <c:if test="${null != rental}">
                <h2><fmt:message key="rental.addNew" /></h2>

                <c:url var="saveUrl" value="/rental/add" />
                <form:form method="POST" role="form" action="${saveUrl}" class="form-horizontal" modelAttribute="rental" commandName="rental">
                    <spring:bind path="customer">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="customer" class="control-label col-sm-2"><fmt:message key="customer" />:</form:label>
                                <div class="col-sm-10">
                                <form:select path="customer" class="form-control">
                                    <form:options items="${customersMap}" />
                                </form:select>
                            </div>
                            <form:errors path="customer" class="control-label col-sm-4"  />
                        </div>
                    </spring:bind>  
                    <spring:bind path="machine">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="machine" class="control-label col-sm-2"><fmt:message key="machine" />:</form:label>
                                <div class="col-sm-10">
                                <form:select path="machine" class="form-control">
                                    <form:options items="${machinesMap}" />
                                </form:select>
                            </div>
                            <form:errors path="machine" class="control-label col-sm-4"  />
                        </div>
                    </spring:bind>   
                    <spring:bind path="dateOfRent">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="dateOfRent" class="control-label col-sm-2"><fmt:message key="rental.dateOfRent" />:</form:label>
                                <div class="col-sm-10">
                                <form:input id="datepicker2" path="dateOfRent" class="form-control"/>
                            </div>
                            <form:errors path="dateOfRent" class="control-label col-sm-4"  />
                        </div>
                    </spring:bind>
                    <spring:bind path="dateOfReturn">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="dateOfReturn" class="control-label col-sm-2"><fmt:message key="rental.dateOfReturn" />:</form:label>
                                <div class="col-sm-10">
                                <form:input id="datepicker" path="dateOfReturn" class="form-control"/>
                            </div>
                            <form:errors path="dateOfReturn" class="control-label col-sm-4"  />
                        </div>
                    </spring:bind>
                    <div class="form-group">        
                        <div class="col-sm-offset-2 col-sm-9">
                            <button type="submit" class="btn btn-default"><fmt:message key="save" /></button>
                            <a href="<c:url value="/rental/index" />" onclick="return confirm('<fmt:message key="cancel.confirm" />')"><fmt:message key="rental.cancelchanges" /></a>
                        </div>
                    </div>

                </form:form>
            </c:if>
        </div>
    </body>
</html>
